﻿using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace Steer
{
    public partial class SeekFleeTest2 : UserControl
    {
        public bool IsFocus = false;

        protected override void OnLostFocus(RoutedEventArgs e)
        {
            IsFocus = false;
            PauseMask.Visibility = IsFocus ? Visibility.Collapsed : Visibility.Visible;
            base.OnLostFocus(e);
        }

        protected override void OnGotFocus(RoutedEventArgs e)
        {
            IsFocus = true;
            PauseMask.Visibility = IsFocus ? Visibility.Collapsed : Visibility.Visible;
            base.OnGotFocus(e);
        }
		public SeekFleeTest2()
		{
			// Required to initialize variables
            InitializeComponent();
            Loaded += new RoutedEventHandler(SeekTest_Loaded);
		}
        void SeekTest_Loaded(object sender, RoutedEventArgs e)
        {

            myA.position = new Vector2D(200, 200);
            myA.edgeBehavior = Vehicle.BOUNCE;
            myB.position = new Vector2D(400, 200);
            myB.edgeBehavior = Vehicle.BOUNCE;
            myC.position = new Vector2D(300, 260);
            myC.edgeBehavior = Vehicle.BOUNCE;

            CompositionTarget.Rendering += new EventHandler(CompositionTarget_Rendering);
        }

        void CompositionTarget_Rendering(object sender, EventArgs e)
        {
            if (IsFocus)
            {
                myA.seek(myB.position);
                myA.flee(myC.position);

                myB.seek(myC.position);
                myB.flee(myA.position);

                myC.seek(myA.position);
                myC.flee(myB.position);

                myA.update();
                myB.update();
                myC.update();
            }
        }
	}
}